// $Id: NetElementShape.cs 125 2007-05-28 16:31:36Z xavex2k $

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using Diagram.Handles;
using Diagram.Model;
using Diagram.View;

namespace PetriDiagram.Shapes
{
    [Serializable]
    public abstract class NetElementShape : RectangularShape
    {
        private List<Handle> handles;

        public override IList<Handle> Handles
        {
            get
            {
                return handles;
            }
        }

        public override void Draw( Graphics g )
        {
            if( IsSelected || IsMouseOver )
                using( Brush brush = new HatchBrush( HatchStyle.DashedHorizontal, Color.Blue, Color.Green ) )
                using( Pen pen = new Pen( brush, 2 ) )
                    g.DrawRectangle( pen, Bounds.Left - 2, Bounds.Top - 2, Bounds.Width + 4, Bounds.Height + 4 );

            g.DrawString( Entity.Name, Settings.Default.NameFont, Brushes.Black, 
                Bounds.Location.X + Bounds.Width, Bounds.Location.Y + Bounds.Height);

            base.Draw( g );
        }

        public NetElementShape()
        {
            handles = new List<Handle>();
        }

        public void EditName()
        {
            Entity e = Entity;
            Diagram.PropertyEditors.StringEditor editor =
                new Diagram.PropertyEditors.StringEditor( e, "Name", true, true, true );

            Rectangle bounds = new Rectangle();

            bounds.Location = new Point( Bounds.Right, Bounds.Bottom );
            bounds.Size = new Size( 50, 40);
            editor.Bounds = bounds;

            EditorHandler.ShowPropertyEditor( editor );
        }

        public Point Middle
        {
            get
            {
                return new Point( Bounds.Left + Bounds.Width / 2,
                                  Bounds.Top + Bounds.Height / 2 );
            }
        }
    }

}
